<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
    <div class="layui-row">
        <!-- 主要内容块 -->
        <div class="layui-col-md12" id="kMainContentCol">
            <div class="layui-fluid wlb-fluid-padding15">
                <div class="layui-card">
                    <form>
                        <div class="layui-form layui-card-header wlb-card-header-auto">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">当前hash值</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="currentHash" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
                                        <i class="layui-icon layui-icon-search"></i>
                                    </button>
                                    <button class="layui-btn " type="reset">
                                        <i class="layui-icon layui-icon-refresh-1"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>

                    <div class="layui-card-body">
                        <table id="kContentTable" lay-filter="kContentTable"></table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>


<!--头部工具栏模板-->
<!--<script type="text/html" id="headToolbarTpl">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="batchdel">删除</button>
</script>-->

<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
    <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="details"><i class="layui-icon layui-icon-about"></i>详情</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="history"><i class="layui-icon layui-icon-console"></i>历史记录</a>
</script>

<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'form', 'layer', 'table'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
        var tableId = 'kContentTable';

        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            , url: BASE_WEB + 'block/info/list/data' //数据接口
            , toolbar: '#headToolbarTpl'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'number', title: '高度', width: 60}
                , {field: 'currentHash', title: '当前哈希', width: 260}
                , {field: 'previousHash', title: '前一个hash', width: 260}
                , {field: 'createTime', title: '创建时间', width: 200}
                , {field: '', title: '操作', width: 235, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        }));
        var area = ['80%', '90%'];
        // 表格行按钮 监听事件
        table.on('tool(' + tableId + ')', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //详情
            if (layEvent === 'details') {
                layer.open({
                    type: 2
                    , title: '数据详情'
                    , content:BASE_WEB + 'block/info/details?businessId=' + data.businessId
                    , maxmin: true
                    , area: area   // 宽高
                    , btn: ['关闭']
                    // , yes: function (index, layero) {
                    //     //点击确认触发 iframe 内容中的按钮提交
                    //     var submit = layero.find('iframe').contents().find("#kFormSubmit");
                    //     submit.click();
                    // }
                });
            }
            //历史
            if (layEvent === 'history') {
                layer.open({
                    type: 2
                    , title: '数据历史'
                    , content:BASE_WEB + 'block/info/history?businessId=' + data.businessId
                    , maxmin: true
                    , area: area  // 宽高
                    , btn: ['关闭']
                    // , yes: function (index, layero) {
                    //     //点击确认触发 iframe 内容中的按钮提交
                    //     var submit = layero.find('iframe').contents().find("#kFormSubmit");
                    //     submit.click();
                    // }
                });
            }

        });

        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params);//
            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
            return false;
        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();

    });
</script>

</body>
</html>